package com.lxblyw.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.lxblyw.entity.FileType;
import com.lxblyw.util.DBHelp;
import com.lxblyw.util.RowMapper;

public class FileTypeDao {
	DBHelp<FileType> db = new DBHelp<FileType>();

	public void save(FileType fileType) {
		String sql = "Insert into t_filetype(id,name,createtime,projectid,employeeid) values(?,?,?,?,?)";
		db.executeSQL(sql, fileType.getId(),fileType.getName(),fileType.getCreatetime(),fileType.getProjectid(),fileType.getEmployeeid());
	}

	public List<FileType> findAll() {
		String sql = "select id,`name`,createtime,projectid,employeeid from t_filetype order by createtime";
		return db.executeQueryForList(sql, new FileTypeRowMapper());
	}
	
	private class FileTypeRowMapper implements RowMapper<FileType> {

		public FileType mapperRow(ResultSet rs) throws SQLException {
			FileType fileType = new FileType();
			fileType.setId(rs.getString("id"));
			fileType.setName(rs.getString("name"));
			fileType.setCreatetime(rs.getString("createtime"));
			fileType.setEmployeeid(rs.getString("employeeid"));
			fileType.setProjectid(rs.getString("projectid"));
			
			return fileType;
		}
		
	}

	public FileType findFileTypeById(String fileTypeId) {
		String sql = "select id,`name`,createtime,projectid,employeeid from t_filetype where id=? order by createtime";
		return db.executeQueryForObject(sql, new FileTypeRowMapper(), fileTypeId);
	}

	public void deleteFileTypeById(String id) {
		String sql = "delete from t_filetype where id=?";
		db.executeSQL(sql, id);
	}
	
}
